{% extends "iphone/base.html" %}

{% block extrahead %}
<script type='text/javascript' src='/appmedia/js/jquery_min.js'></script>
<script language="JavaScript" type="text/javascript">
function TaskIsDone(id) {
		$.post('/task_is_done/', {"id": id}, function(data){ in_ajax = 0;});
		var el = document.getElementById("task_is_done"+id); 
		if (el.alt == "undone") {
			el.src = "/appmedia/done.gif";
			el.alt = "done";
		}
		else {
			el.src = "/appmedia/undone.gif";
			el.alt = "undone";
		}
	}

function ShowForm(el) {
	var wnd = document.getElementById(el);
	wnd.style.display = 'inline';
	wnd.style.visibility='visible';
	document.getElementById('id_name_'+el).focus();
	}

function HideForm(el) {
	var wnd = document.getElementById(el);
	wnd.style.display = 'none';
	wnd.style.visibility='hidden';
	}
</script>
{% endblock %}

{% block content %}
<div class="header">
<!-- Whiteboard :: -->
<a href="javascript:HideForm('add_pr_wnd');ShowForm('add_item_wnd')">
<img src="/appmedia/add.gif" />
Add task
</a>
::
<a href="/iphone/archive_all_done_tasks/">
<img src="/appmedia/delete.gif" />
Archive done
</a>
::
<a href="/iphone/offline/">
<img src="/appmedia/go_offline.gif" />
<span style="color:red">Work offline</span>
</a>
</div>

<div class="header">
<a href="/iphone/hottasks/">
<img src="/appmedia/hot.gif" />
Hot tasks
</a>
::
<a href="/iphone/share_tasks/">
<img src="/appmedia/share.gif" />
Share tasks
</a>
::
<a href="javascript:HideForm('add_item_wnd');ShowForm('add_pr_wnd')">
<img src="/appmedia/add.gif" />
New project
</a>
</div>

{% if deleted_name %}
<div class="undo">
<a href="/iphone/undo/">Archived {{deleted_name|lower}}. Undo?</a>
</div>
{% endif %}

<div id="add_item_wnd" style="visibility:hidden;display:none;">
<form id="add_item_form" method="POST" action='/iphone/task/add/'>
	<input id="id_name_add_item_wnd" name="name" type="text" style="width:95%">
	<input type="hidden" name="time_spent" value="0.0">

	<div class="header">
		<input class="submit" type="submit" value="Save task">
		::
		<a href="javascript:HideForm('add_item_wnd')">
		Cancel
		</a>
		::
		<a href="/iphone/task/add/">
		Edit task details &gt;&gt;
		</a>
	</div>
</form>
</div>

<div id="add_pr_wnd" style="visibility:hidden;display:none;">
<form id="add_pr_form" method="POST" action='/iphone/project/add/'>
	<input id="id_name_add_pr_wnd" name="name" type="text" style="width:95%">
	<input type="hidden" name="hour_rate" value="0.0">

	<div class="header">
		<input class="submit" type="submit" value="Add project">
		::
		<a href="javascript:HideForm('add_pr_wnd')">
		Cancel
		</a>
	</div>
</form>
</div>

<table cellpadding="0" class="tab">
{% if tasks %}
	{% for task in tasks %}
	<div class="task_item">
	{% if task.done %}
		<img id="task_is_done{{task.id}}" src="/appmedia/done.gif" onclick="javascript:TaskIsDone({{task.id}})" alt="done" />
	{% else %}
		<img id="task_is_done{{task.id}}" src="/appmedia/undone.gif" onclick="javascript:TaskIsDone({{task.id}})" alt="undone" />
	{% endif %}
	
	<span class="info">{{forloop.counter}}</span> 
	
	<a accesskey="{{forloop.counter}}" href="/iphone/task/edit/{{task.id}}/">{{task.name}}</a>
	<span class="info">
	{% if task.project %}
		- {{task.project}}
	{% endif %}
	
	{% if task.task_date %}
		{{task.task_date}}
	{% endif %}
	
	{{task.time_spent|floatformat:1}} h
	</span>
	</div>
	{% endfor %}
{% endif %}
</table>
<p>&nbsp;</p>
<b class="nifty"></b>
<p style="background:#fad163;margin:0px;padding:2px;">
{{ motivation|escape }} 
<span class="light">
{% if motivation.author %}
    {{ motivation.author }}
{% else %}
    Unknown author
{% endif %}
</span>
</p>
<b class="nifty"></b>

{% endblock %}
